package com.hecore.lagou.speak.soft;

import com.hecore.lagou.speak.entity.SpeakBeanSort;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: hecore
 * @Date: 2020/10/18 23:50
 * @Description: 排序Mapper
 * ullWritable是Writable的一个特殊类，实现方法为空实现，不从数据流中读数据，也不写入数据，只充当占位符，如在MapReduce中，如果你不需要使用键或值，你就可以将键或值声明为NullWritable,NullWritable是一个不可变的单实例类型。
 */

public class SortMapper extends Mapper<LongWritable, Text, SpeakBeanSort,
        NullWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        final String[] arr = value.toString().split("\t");
        final SpeakBeanSort bean = new SpeakBeanSort(Long.parseLong(arr[1]),
                Long.parseLong(arr[2]), arr[0]);
        context.write(bean, NullWritable.get());
    }
}
